package com.bolt.support.freemarker;

import com.bolt.common.io.resource.ResourceMode;
import com.bolt.common.utils.CharsetUtil;
import lombok.Data;

import java.io.Serializable;
import java.nio.charset.Charset;

@Data
public class TemplateConfig implements Serializable {

    /**
     * 编码
     */
    private Charset charset;
    /**
     * 模板路径，如果ClassPath或者WebRoot模式，则表示相对路径
     */
    private String path;

    /**
     * 模板资源加载方式
     */
    private ResourceMode resourceMode;


    public TemplateConfig(Charset charset, String path, ResourceMode resourceMode) {
        this.charset = charset;
        this.path = path;
        this.resourceMode = resourceMode;
    }

    public TemplateConfig(String path) {
        this(path, ResourceMode.STRING);
    }

    public TemplateConfig(String path, ResourceMode resourceMode) {
        this(CharsetUtil.CHARSET_UTF_8, path, resourceMode);
    }


    public String getCharsetStr() {
        if (null == this.charset) {
            return CharsetUtil.CHARSET_UTF_8.toString();
        }
        return this.charset.toString();
    }


}

 